package com.example.tianling.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.tianling.dao.*;
import com.example.tianling.entity.*;
import com.example.tianling.service.VideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VideosServiceImpl
        extends ServiceImpl<VideosMapper, VideosEntity>
        implements VideosService {
    @Autowired
    private VideosMapper videosMapper;

    //加载文章
    public List<VideosEntity> getVideosList(){
        QueryWrapper<VideosEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","title","subtitle","description","view_count","video","ranks");
        queryWrapper.orderByDesc("ranks");
        return videosMapper.selectList(queryWrapper);
    };
    public VideosEntity click(Integer videoId){
        UpdateWrapper<VideosEntity> wrapper = new UpdateWrapper();
        wrapper.eq("id",videoId);
        wrapper.setSql("view_count = view_count + 1");
        videosMapper.update(null,wrapper);
        return videosMapper.selectById(videoId);
    };

}
